Support facet formulas y~1 and 1~x for 1-column or 1-row layouts#562
Support facet formulas y~1 and 1~x for 1-column or 1-row layouts#562
Conversation
… formula part contains no variables (e.g., just a constant)
|
Thanks @zeileis.
Minor comment: but why not just use Regarding your plots... Hmmm, I'm not sure that I like the "formula" output. Taking the very top plot as an example, why do we have a duplicate "Gentoo-Biscoe" facet label on the right (but none of the other groups)? Ideally, these should give the exact same output as the Regarding 2, yes I agree. Ideally, we would have some singular (modular) code that both "methods" can call. It's been a long time since I wrote that up, and can't remember my exact reason. It might just have been the simplest solution at the time, even though it incurred a bit of tech debt. |
|
Regarding your three comments/questions: When using Correct, the formula-based output is currently not ideal. Apologies for not bringing this out clearly. I also think that we should get the same output as via Should I try to replace |
|
Thanks @zeileis. Appreciate the clarifications. Stepping back for a sec, I'm planning to submit a patch 0.6.1 release to CRAN imminently---in part, b/c I'm trying to update my maintainer email across all of my packages. I was hoping to get this PR (and #558) in as part of the submission, but it seems that we still have a bit of work to do. So I think it's best to leave these out for the moment and we can address afterwards. Hope that's okay? |
|
Sure, perfectly fine! 🚀 |
In #558 we discussed the idea that
facet = y ~ 1could be used as a shortcut forfacet = ~ y, facet.args = list(nrow = length(unique(y))). Analogously,facet = 1 ~ xcould be used as a shortcut forfacet = ~ x, facet.args = list(nrow = 1).I have implemented this now by tweaking
tinyframe()slightly. This now distinguishes~ xfrom1 ~ xby returningNULLfor theyfacetin the former case but a zero-column data frame in the latter case. In other words, a zero-column data frame signals: This part of the formula had a specification but no variables in it. Intinyplot.formula()I've extended the processing ofxfacetandyfacetcorrespondingly.In principle, this works but there are two caveats:
tinyplot.default()handles the case withfacet.argsslightly differently from facet attributes.get_facet_fml()(https://github.com/grantmcdermott/tinyplot/blob/facet-formula/R/facet.R#L613-L658) that does something similar to mytinyformula()/tinyframe()processing but is only used in the default method. We should probably try to use the same code in both cases.To illustrate the first point, consider
Note that in the formula-based specification we get the right facet strips as well. Probably this should only be done in case both the number of rows and the number of columns is greater than 1? I wasn't sure though where to best add this information.